package cepicam.src.view;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;

import javax.swing.table.AbstractTableModel;

import cepicam.src.domain.Paiement;


public class ListePaiementTableModel extends AbstractTableModel {
	
	private final ArrayList<Paiement> listpaie;
	private final String [] entetes = {"Date", "Montant", "Type"};
	
	
	public ListePaiementTableModel(ArrayList<Paiement> listpaie){
		super();
		this.listpaie = listpaie;
		
	}
	
	public int getRowCount(){
		return listpaie.size();
	}
	
    public int getColumnCount() {
        return entetes.length;
    }

    public String getColumnName(int columnIndex) {
        return entetes[columnIndex];
    }

    public Object getValueAt(int rowIndex, int columnIndex) {    	
    	
        switch(columnIndex){
        case 0 :
        	GregorianCalendar dateGreg = listpaie.get(rowIndex).getDate();
       	 
        	DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        	java.util.Date dateDate = dateGreg.getTime();
        	 
        	String retour = dateFormat.format(dateDate);
            return retour;
            
        case 1:
            return listpaie.get(rowIndex).getMontant();
        case 2:
            return listpaie.get(rowIndex).getType();
        default:
            return null; 
        }
    }
    
    public Paiement getValueAt(int rowIndex){
    	return listpaie.get(rowIndex);
    }
}
